home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / macabuse / imlib / timer.c < prev    next >
C/C++ Source or Header  |  1997-05-20  |  2KB  |  103 lines

  1. #include "system.h"
  2.  
  3. #ifdef __UNIX_XWIN
  4. #include <stdio.h>
  5. #include <sys/time.h>
  6. #include <stdlib.h>
  7. #include <signal.h>
  8. #include <unistd.h>
  9. #include <signal.h>
  10.  
  11.  
  12. //#ifndef setitimer
  13. //extern "C" {
  14. //int setitimer(int Which, struct itimerval *Value,
  15. //                struct itimerval *Ovalue);
  16. //} ;
  17. //#endif
  18.  
  19. struct sigaction sa;
  20. typedef void (*int_handler)();
  21. #define SETSIG(sig,fun) (int_handler)sa.sa_handler=fun; \
  22.             sa.sa_flags=0; \
  23.             sigemptyset(&sa.sa_mask); \
  24.             sigaddset(&sa.sa_mask,SIGALRM); \
  25.             sigaction(sig,&sa,NULL);
  26.  
  27.  
  28.  
  29. //void timer_handler()
  30. //{
  31. //  SETSIG(SIGALRM,timer_handler);
  32. //  printf("%ld\n",jclock++);
  33. //  fflush(stdout);
  34. //}
  35.  
  36.  
  37. void init_timer(int_handler int_proc, long utime)
  38. {
  39.   itimerval newt;
  40.   SETSIG(SIGALRM,int_proc);
  41.   newt.it_interval.tv_sec=0;
  42.   newt.it_interval.tv_usec=utime;
  43.   newt.it_value.tv_sec=0;
  44.   newt.it_value.tv_usec=utime;
  45.   setitimer(ITIMER_REAL,&newt,NULL);
  46. }
  47. #else
  48.   #ifdef __BCPLUSPLUS__
  49.   #include <stdio.h>
  50.   #include <dos.h>
  51.   #include <conio.h>
  52.  
  53.   #define INTR 0X1C    /* The clock tick interrupt */
  54.   void interrupt ( *oldhandler)(...);
  55.  
  56.   int count=0;
  57.  
  58.   void interrupt handler(...)
  59.   {
  60.   /* increase the global counter */
  61.      count++;
  62.  
  63.   /* call the old routine */
  64.      oldhandler();
  65.   }
  66.  
  67.   int main(void)
  68.   {
  69.   /* save the old interrupt vector */
  70.      oldhandler = getvect(INTR);
  71.  
  72.   /* install the new interrupt handler */
  73.      setvect(INTR, handler);
  74.  
  75.   /* loop until the counter exceeds 20 */
  76.      while (count < 20)
  77.     printf("count is %d\n",count);
  78.  
  79.   /* reset the old interrupt handler */
  80.      setvect(INTR, oldhandler);
  81.  
  82.      return 0;
  83.   }
  84.  
  85.  
  86.  
  87.   #else
  88.   #error Timer not supported for this compiler! Use Borland or gcc
  89.   #endif
  90. #endif
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.